<template>
    <div class="single-page">
        <div class="card-head" :style="{
            backgroundImage: `url('${api_base_url}images/team.png')`
        }">
            <h2><span class="iconfont icon-back" @click="goback()"></span>{{category.title}}</h2>
        </div>
        <p class="description" v-html="category.description"></p>
        <div class="content" v-html="category.content"></div>
    </div>
</template>
<script>
    import NavBar from './Nav-Bar';
    import { router } from '../routes';
    import config, { fetchRest } from '../config';

    export default {
        name: "single-page",
        components: { NavBar },

        data() {
            this.fetchData();

            var res = {
                api_base_url: config.api_base_url,
                category: {},
                some_model_categorys: [],
                page_data: {
                    data: [],
                    paging: {}
                },
                hot_records: [],
                loading: true
            };
            return res;
        },
        watch: {
            // 监听路由变动
            '$route': 'fetchData'
        },
        computed: {
        },
        methods: {
            async fetchData() {
                this.loading = true;
                const category_name = router.currentRoute.params.category;

                var data = await fetchRest("category/" + category_name + "?disable_hot_records=true&disable_some_model_categorys=true");

                for (var k in data) {
                    this[k] = data[k];
                }
                this.loading = false;
            },
            goback(){
                router.back();
            }
        }
    }
</script>

<style scoped>
    .card-head{
        background-size: contain;
        background-position-x: right;
        background-repeat: no-repeat;
        background-color: rgb(77, 182, 172);
        height: 86px;
        overflow: hidden;
        color:#FFF;
        text-align:left;
        padding: 0 16px;
        display: flex;
        /*justify-content:space-between;*/
    }
    .card-head h2{
        margin-top: 20px;
        display: inline-block;
        flex: 1 0 auto;
    }
    .card-head .icon-back{
        padding-right: 1em;
        border-right: 1px solid #eee;
        margin-right: 1em;
    }
    .placeholder-mide{
        width: 100%;
    }
    .page-turn{
        font-family: Arial, Helvetica, sans-serif;
        margin-top: 45px;
        display: inline-block;
        flex: 1 0 auto;
        font-size: 1.4em;
        color: #EEE;
    }
    .page-turn .iconfont.icon-turnpage{
        font-size: 1em;
        color: #EEE;
    }
    .page-turn .iconfont{
        font-size: 1.4em;
        font-weight: lighter;
        color: #FFF;
        text-shadow: 0 0 2px #333;
    }
    .page-turn .iconfont.disabled{
        color: #CCC;
        text-shadow:none;
    }
    .content{
        text-align: left;
        padding: 15px;
        margin-bottom: 70px;
    }
</style>